package com.doone.telmarket.domain.factory;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import com.doone.telmarket.domain.SiteFile;

/**
 * 
 * @author 吴同庆
 * @date 2009-9-18
 * @description 站点文件工厂
 * @package     com.doone.telmarket.domain.factory
 */
@Service
public class SiteFileFactory {
	
	private static final String DELIMITER_REGEX = "\\.";

	private static final String FILE_NAME_REGEX = "[\\w\\-]+\\.\\w+";
	
	private boolean matchName(String fileName) {
		String regex = FILE_NAME_REGEX;
		boolean isMatch = fileName.matches(regex);
		return isMatch;
	}
	
	
	public SiteFile createSiteFile(String oldName,String replacement){
		if(matchName(oldName)){
			String[] nameArray = StringUtils.split(oldName, DELIMITER_REGEX);
			SiteFile siteFile = new SiteFile(replacement,nameArray[1]);
			return siteFile;
		}
		else{
			throw new RuntimeException("文件名非法，请检查");
		}
	}
	
	public SiteFile createPage(String pageName){
		SiteFile siteFile = new SiteFile(pageName);
		return siteFile;
	}

}
